package com.platform.mobile.operator;

import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.platform.base.SysException;
import com.platform.bean.PageInfo;
import com.platform.mobile.bean.GetTransferRequest;
import com.platform.mobile.bean.GetTransferResponse;
import com.platform.mobile.bean.LoginAssitantInfo;
import com.platform.mobile.bean.ReqBean;
import com.platform.mobile.bean.ResBean;
import com.platform.mobile.bean.ResultBean;
import com.platform.mobile.factory.Operator;
import com.platform.mobile.service.PaitentService;
import com.platform.mobile.session.SessionManager;

@Component
public class GetTransfer extends Operator{

	private static Logger log = LoggerFactory.getLogger(GetTransfer.class);
	
	@Autowired
	private PaitentService service;
	
	@SuppressWarnings("unchecked")
	@Override 
	public ResBean operate(ReqBean reqBean) throws SysException {
	
		log.info("进入到GetPatient业务处理类，处理[" + reqBean.getClientInfo() + "]用户请求");
		
		ResBean resBean = new ResBean();
		resBean.setClientInfo(reqBean.getClientInfo());
		resBean.setJsonrpc("2.0");
		resBean.setMethod("GetPatient");
		ResultBean result = new ResultBean();
		
		GetTransferRequest request = new GetTransferRequest();
		GetTransferResponse response = new GetTransferResponse();
		
		try{
			
			Object params = reqBean.getParams();
			if(params != null){
				
				LinkedHashMap<String, Object> paramMap 
					= (LinkedHashMap<String, Object>)params;
				request.setIsTransfer((Integer)paramMap.get("isTransfer"));
				LinkedHashMap<String, Object> pageInfoMap
					= (LinkedHashMap<String, Object>)paramMap.get("pageInfo");
				PageInfo pageInfo = new PageInfo();
				pageInfo.setCurrPage((Integer)pageInfoMap.get("currPage"));
				pageInfo.setPageSize((Integer)pageInfoMap.get("pageSize"));
				request.setPageInfo(pageInfo);
				
				Object session 
					= SessionManager.getInstance()
					.getSessionInfo(reqBean.getSessionID());
				Integer deptId 
					= ((LoginAssitantInfo)session).getDept_id();
				
				response = service.getTransferView(request, deptId);
				
				result.setResultStatus("1");
				result.setInfo("获取转诊记录列表成功");
				result.setData(response);
			}
			
		}catch(Exception e){
			e.printStackTrace();
			result.setResultStatus("0");
			result.setInfo("服务器异常");
			result.setData(response);
		}
		
		resBean.setResult(result);
		return resBean;
	}

}
